﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Entidades.Responses;
using Agente.App_Code;
using log4net;

namespace Agente
{
    /// <summary>
    /// Summary description for AgenteService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    
    public class AgenteService : System.Web.Services.WebService
    {
        IRequestHandler _req = new RequestHandler();
        public static readonly ILog log = LogManager.GetLogger(typeof(AgenteService));

        [WebMethod]
        public MemoryResponse ObtenerMemoria()
        {
            try
            {
                AgenteService.log.Info("Consulta de memoria");            

                MemoryResponse res =  _req.ObtenerMemoria();
                if (res == null)
                    AgenteService.log.Info("La consulta de ObtenerMemoria retorno null");                
                return res;
            }
            catch (Exception ex)
            {
                log.Error("ObtenerMemoria", ex);
                return null;
            }
        }

        [WebMethod]
        public DiscoResponse ObtenerDisco()
        {
            try
            {
                AgenteService.log.Info("Consulta de Disco");            
                DiscoResponse res = _req.ObtenerDisco();
                if (res == null)
                    AgenteService.log.Info("La consulta de ObtenerDisco retorno null");             
                return res;
            }
            catch (Exception ex)
            {
                log.Error("ObtenerDisco", ex);
                return null;
            }
        }

        [WebMethod]
        public CpuResponse ObtenerCpu()
        {
            try
            {
                AgenteService.log.Info("Consulta de CPU");            
                CpuResponse res= _req.ObtenerCpu();
                if (res == null)
                    AgenteService.log.Info("La consulta de ObtenerCpu retorno null");                
                return res;

            }
            catch (Exception ex)
            {
                log.Error("ObtenerCpu", ex);
                return null;
            }
        }
    }
}
